package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.annotation.Anonymous;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RentalAdministrator;
import com.ruoyi.system.service.IRentalAdministratorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租房管理员Controller
 * 
 * @author ruoyi
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/system/rentaladmin")
public class RentalAdministratorController extends BaseController
{
    @Autowired
    private IRentalAdministratorService rentalAdministratorService;

    /**
     * 查询租房管理员列表
     */
    @PreAuthorize("@ss.hasPermi('system:rentaladmin:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalAdministrator rentalAdministrator)
    {
        startPage();
        List<RentalAdministrator> list = rentalAdministratorService.selectRentalAdministratorList(rentalAdministrator);
        return getDataTable(list);
    }

    /**
     * 获取租房管理员
     */
    @Anonymous
    @GetMapping(value = "/getRentalAdministratorByIsadmin/{isadmin}")
    public AjaxResult getRentalAdministratorByIsadmin(@PathVariable("isadmin") String isadmin)
    {
        return success(rentalAdministratorService.getRentalAdministratorByIsadmin(isadmin));
    }

    /**
     * 导出租房管理员列表
     */
    @PreAuthorize("@ss.hasPermi('system:rentaladmin:export')")
    @Log(title = "租房管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentalAdministrator rentalAdministrator)
    {
        List<RentalAdministrator> list = rentalAdministratorService.selectRentalAdministratorList(rentalAdministrator);
        ExcelUtil<RentalAdministrator> util = new ExcelUtil<RentalAdministrator>(RentalAdministrator.class);
        util.exportExcel(response, list, "租房管理员数据");
    }

    /**
     * 获取租房管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rentaladmin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rentalAdministratorService.selectRentalAdministratorById(id));
    }

    /**
     * 新增租房管理员
     */
    @PreAuthorize("@ss.hasPermi('system:rentaladmin:add')")
    @Log(title = "租房管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalAdministrator rentalAdministrator)
    {
        rentalAdministrator.setCreateBy(getUsername());
        return toAjax(rentalAdministratorService.insertRentalAdministrator(rentalAdministrator));
    }

    /**
     * 修改租房管理员
     */
    @PreAuthorize("@ss.hasPermi('system:rentaladmin:edit')")
    @Log(title = "租房管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalAdministrator rentalAdministrator)
    {
        rentalAdministrator.setUpdateBy(getUsername());
        return toAjax(rentalAdministratorService.updateRentalAdministrator(rentalAdministrator));
    }

    /**
     * 删除租房管理员
     */
    @PreAuthorize("@ss.hasPermi('system:rentaladmin:remove')")
    @Log(title = "租房管理员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rentalAdministratorService.deleteRentalAdministratorByIds(ids));
    }
}
